package com.stylefeng.guns.modular.attendance.controller;

import com.stylefeng.guns.core.base.controller.BaseController;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.DoorAttendance;
import com.stylefeng.guns.modular.attendance.service.IDoorAttendanceService;

import java.util.List;

/**
 * 出勤日志控制器
 *
 * @author fengshuonan
 * @Date 2018-09-12 14:06:12
 */
@Controller
@RequestMapping("/doorAttendance")
public class DoorAttendanceController extends BaseController {

    private String PREFIX = "/attendance/doorAttendance/";

    @Autowired
    private IDoorAttendanceService doorAttendanceService;

    /**
     * 跳转到出勤日志首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "doorAttendance.html";
    }

    /**
     * 跳转到添加出勤日志
     */
    @RequestMapping("/doorAttendance_add")
    public String doorAttendanceAdd() {
        return PREFIX + "doorAttendance_add.html";
    }

    /**
     * 跳转到修改出勤日志
     */
    @RequestMapping("/doorAttendance_update/{doorAttendanceId}")
    public String doorAttendanceUpdate(@PathVariable Integer doorAttendanceId, Model model) {
        DoorAttendance doorAttendance = doorAttendanceService.selectById(doorAttendanceId);
        model.addAttribute("item",doorAttendance);
        LogObjectHolder.me().set(doorAttendance);
        return PREFIX + "doorAttendance_edit.html";
    }

    /**
     * 获取出勤日志列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
//    public Object list(String condition) {
//        return doorAttendanceService.selectList(null);
//    }
    public Object list(String name,String depaetment,String status) {
        List<DoorAttendance> listAtt = doorAttendanceService.getDoorAttendance(name,depaetment, status);

        return listAtt;
    }
    /**
     * 新增出勤日志
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(DoorAttendance doorAttendance) {
        doorAttendanceService.insert(doorAttendance);
        return SUCCESS_TIP;
    }

    /**
     * 删除出勤日志
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer doorAttendanceId) {
        doorAttendanceService.deleteById(doorAttendanceId);
        return SUCCESS_TIP;
    }

    /**
     * 修改出勤日志
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(DoorAttendance doorAttendance) {
        doorAttendanceService.updateById(doorAttendance);
        return SUCCESS_TIP;
    }

    /**
     * 出勤日志详情
     */
    @RequestMapping(value = "/detail/{doorAttendanceId}")
    @ResponseBody
    public Object detail(@PathVariable("doorAttendanceId") Integer doorAttendanceId) {
        return doorAttendanceService.selectById(doorAttendanceId);
    }
}
